<?php
namespace Deployer;

require 'recipe/laravel.php';

// Project name
set('application', 'laravel-base');

// Project repository
set('repository', 'https://gitee.com/subowen_admin/laravel-base.git');

// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);

// Shared files/dirs between deploys
add('shared_files', []);
add('shared_dirs', []);

// Writable dirs by web server
add('writable_dirs', []);
set('allow_anonymous_stats', false);
set('default_stage', 'local');

// Hosts

host('122.112.185.206')
    ->user('chenshengwen')
    ->stage('prod')
    ->set('deploy_path', '/hwdata/www/{{application}}');

localhost()
    ->stage('local')
    ->roles('test', 'build');

// Tasks

task('git:push', function() {
    writeln('start git push task');
    run('git add .');
    run('git commit -m "auto commit by deploy"');
    run('git push origin master');
});

task('build', function () {
    run('cd {{release_path}} && build');
});

desc('Restart nginx+php service');
task('np:restart', function () {
    run('sudo systemctl restart php-fpm', ['tty' => true]);
    run('sudo systemctl restart nginx', ['tty' => true]);
});


// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.

before('deploy:symlink', 'artisan:migrate');

// after('deploy:symlink', 'artisan:route:clear');
after('deploy:symlink', 'np:restart');

